package views;

import java.awt.CardLayout;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;

import views.button.NoobButton;

public class ToolPanel extends JPanel implements ActionListener{
	NoobButton retry ;
	NoobButton prev ;
	NoobButton next ;
	NoobButton edit ;
	NoobButton map ;
	NoobButton help ;
	GameView gameView;
	public ToolPanel(GameView gameView){
		this.gameView = gameView;
		retry = new NoobButton("Retry");
		retry.setActionCommand("retry");
		retry.addActionListener(this);
		
		prev = new NoobButton("Prev");
		prev.setActionCommand("prev");
		prev.addActionListener(this);
		
		next = new NoobButton("Next");
		next.setActionCommand("next");
		next.addActionListener(this);
		
		map = new NoobButton("Choose Map");
		map.setActionCommand("map");
		map.addActionListener(this);
		
		help = new NoobButton("Help");
		help.setActionCommand("help");
		help.addActionListener(this);
		
		edit = new NoobButton("Edit/Create");
		edit.setActionCommand("edit");
		edit.addActionListener(this);
		
		add(retry);
		add(prev);
		add(next);
		add(map);
		add(help);
		add(edit);
	}
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		Graphics2D g2 = (Graphics2D)g;
		GradientPaint gp = new GradientPaint(0,0,Color.white,0,getHeight(),Color.gray);
		g2.setPaint(gp);
		g2.fillRect(0,0,getWidth(),getHeight());
	}
	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		String cmd = arg0.getActionCommand();
		if("retry".equals(cmd)){
			gameView.stageView.stage.intiStage();
			gameView.stageView.repaint();
		}else if("edit".equals(cmd)){
			gameView.stageView.isEditmode=true;
			((CardLayout)(gameView.menuView.getLayout())).show(gameView.menuView,"edit");
		}else if("next".equals(cmd)){
			gameView.stageView.stage.nextLevel();
			gameView.stageView.repaint();
		}else if("prev".equals(cmd)){
			gameView.stageView.stage.prevLevel();
			gameView.stageView.repaint();
		}
	}
}
